package com.ruoyi.web.core;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class AplicationInit implements CommandLineRunner {

    @Autowired
    Environment env;

    @Autowired
    SentenceService sentenceService;

    @Override
    public void run(String... args) throws Exception {
        log.info("");
        log.info("=== APPLICATION ENVIROMENT ===");

        info("spring.profiles.active");
        info("server.servlet.context-path");
        info("server.port");
        info("spring.datasource.druid.master.url");

        sentenceService.apiSentence();

        log.info("=== APPLICATION ENVIROMENT ===");
        log.debug("");
    }

    private String info(String prop) {
        String property = env.getProperty(prop);
        log.info("ENV[ {} ] ==> {}", prop, property);
        return property;
    }
}
